package servelet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.User;
import jdbc.UsrDao;

/**
 * Servlet implementation class Usr_register
 */
@WebServlet("/Usr_register")
public class Usr_register extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Usr_register() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String na=request.getParameter("user");
		String pa=request.getParameter("psw1");
		String te=request.getParameter("telephone");
		String ad=request.getParameter("adress");
		String re=request.getParameter("realname");
		
		PrintWriter out= response.getWriter();
		//out.print(na+pa);
		User usr= new User(na,pa);
		UsrDao usd = new UsrDao();
		usd.ReginUsr(usr);
		if(na!=null){
			response.sendRedirect("index.jsp");
		}
		if (ad==null||re==null){
			response.sendRedirect("MyCenter.jsp");
		}
	}

}
